// 使用函数模板排序

#include <iostream>
using namespace std;

template <typename T>
void myswap(T &a, T &b)
{
    T temp = a;
    a = b;
    b = temp;
}

template <typename T>
void sort(T arr[], int len)
{
    for (int i = 0; i < len; i++)
    {
        int max = i;
        for (int j = i + 1; j < len; j++)
        {
            if (arr[max] < arr[j])
            {
                max = j;
            }
        }
        if (max != i)
        {
            myswap(arr[i], arr[max]);
        }
    }
}

template <typename T>
void print_arr(T arr[], int len)
{
    for (int i = 0; i < len; i++)
    {
        cout << arr[i] << " ";
    }
    cout << endl;
}

void test01()
{
    // 测试char数组
    char arr[] = "acdhscslgesd";
    int num = sizeof(arr) / sizeof(char);
    sort(arr, num);
    print_arr(arr, num);
}

void test02()
{
    // 测试int数组
    int arr[] = {5, 3, 2, 5, 3, 6, 1};
    int num = sizeof(arr) / sizeof(int);
    sort(arr, num);
    print_arr(arr, num);
}

int main()
{
    test01();

    test02();

    return 0;
}